#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# pip install pynput
from pynput import keyboard

def on_press(key):
    try:
        print('普通按键: {0} 按下'.format(
            key.char))
        print key
    except AttributeError:
        print('特殊按键: {0} 按下'.format(
            key))


def on_release(key):
    print('按键: {0} 弹起'.format(
        key))
    if key == keyboard.Key.f12:
        # Stop listener
        return False


# Collect events until released
with keyboard.Listener(
        on_press=on_press,
        on_release=on_release) as listener:
    listener.join()

# ...or, in a non-blocking fashion:
listener = keyboard.Listener(
    on_press=on_press,
    on_release=on_release)
listener.start()
